function getRandomInt(min, max) {
  // 返回两个数的打乱数
  return Math.floor(Math.random() * (max - min + 1) + min);
}

export function shuffle(arr) {
  let _arr = arr.slice();
  for (let i = 0; i < _arr.length; i++) {
    let j = getRandomInt(0, _arr.length - 1);
    let t = _arr[i];
    _arr[i] = _arr[j];
    _arr[j] = t;
  }
  return _arr;
}

export function debounce(func, delay) {
  let timer = null;
  return (...args) => {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      func.apply(this, args);
    }, delay);
  };
}

/* 封装歌曲当前播放时间 */
export function format(interval) {
  interval = interval | 0;
  var min = (interval / 60) | 0;
  var sec = interval % 60;
  if (sec.toString().length === 1) {
    sec = `0${sec}`;
  }
  return `${min}:${sec}`;
}

export function transferTime(interval) {
  const m = Math.floor(interval / 60);
  const s = interval - m * 60;
  const dt = `${m * 60  + s}.000`;
  return parseFloat(dt) * 1000;
}

export function getPlayCount(num) {
  if (num < 9999) {
    return num
  }
  const count = Math.floor(num / 10000);
  if (count <= 9999) {
    return `${count} 万`;
  }
  if (count <= 99999) {
    return `${count / 10000} 亿`;
  }
  return `∞`;
}